<?php 
// 广告主
namespace Admin\Model;
use Think\Model;
class AdvertiserModel extends Model {
	 protected $tableName = 'advertiser';

	 protected $_validate = array(
     array('account','require','账号不能为空！'), 
     // array('account','','帐号名称已经存在！',0,'unique',1),   
     array('account','/^[a-zA-z]\w{3,15}$/','帐号名为4-16位字母开头数字下划线组成！',0,'regex',3), 

    
     array('password','/^(\w){6,20}$/','帐号名为6-20位字母数字下划线组成！',0,'regex',3), 

     array('company_name','require','公司名不能为空！'), 
     // array('company_name','','公司名称已经存在！',0,'unique',1),   
     array('contact_name','require','联系人不能为空！'), 
     array('contact_phone','require','联系人电话不能为空！'), 
     array('business_id','require','所属商务不能为空！'), 
   );

   protected $_auto = array ( 
     array('account_status','1'),   
     array('add_time','time','1'),   
     array('balance','0','1'),  
     
	 );


   public function checkInvoice($id='')
   {


        $invoice_type=$this->where(['id'=>$id])->getField('invoice_type');
        
        if (is_null($data['invoice_type'])) {
            return false;
        } 


        if ($invoice_type=='1') {
            $data=$this->field('content_type,invoice_header,duty_paragraph,opening_bank,registered_address,company_phone')->find();

        }

        if($invoice_type=='2'){
             $data=$this->field('content_type,invoice_header,duty_paragraph')->find();
        }

        foreach ($data as $key => $value) {
            if (empty($value)) {
                return false;
            }
        }

        return true;

   }

   // 开票信息详情
   public function invoiceInfo($id='',&$arr)
   {
       $data=$this->find($id);

       
       if (!empty($data)&&!is_null($data['invoice_type'])) {      

           if ($data['invoice_type']=='1') {
               $data_new= $this->field('content_type,invoice_header,duty_paragraph,opening_bank,registered_address,company_phone,invoice_type')->create($data);
           }

           if ($data['invoice_type']=='2') {
               $data_new= $this->field('content_type,invoice_header,duty_paragraph,invoice_type')->create($data);
           }

           $arr=$data_new;
           return true;
       }else{

            return false;
       }



   }


}


?>